<template>
    <div class="app-container">
      <el-form :model="queryParams" ref="queryForm" :inline="true" v-show="showSearch" label-width="110px">
        <el-form-item label="技师姓名" prop="name">
          <el-input v-model="queryParams.name" placeholder="请输入技师姓名" clearable size="small"
            @keyup.enter.native="handleQuery" />
        </el-form-item>
        <el-form-item label="技师电话" prop="phonenumber">
          <el-input v-model="queryParams.phonenumber" placeholder="请输入技师电话" clearable size="small"
            @keyup.enter.native="handleQuery" />
        </el-form-item>
        <el-form-item label="技师出生年月日" prop="birthday">
          <el-date-picker @change="birthdayDataChange" v-model="birthdayData" type="daterange" range-separator="至"
                  start-placeholder="开始日期" end-placeholder="结束日期" value-format="yyyy-MM-dd">
                </el-date-picker>
        </el-form-item>
        <el-form-item label="性别" prop="sex">
          <el-select multiple v-model="queryParams.sex" placeholder="请选择性别">
            <el-option v-for="contract in sexArray" :key="contract.dictValue" :label="contract.dictLabel"
              :value="contract.dictValue"></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="申请时间" prop="createTime">
          <el-date-picker @change="createTimeChange" v-model="createTimeDate" type="daterange" range-separator="至"
                  start-placeholder="开始日期" end-placeholder="结束日期" value-format="yyyy-MM-dd">
                </el-date-picker>
        </el-form-item>
        <el-form-item label="所在城市" prop="areaName">
          <el-input v-model="queryParams.city" placeholder="请输入所在城市" clearable size="small"
            @keyup.enter.native="handleQuery" />
        </el-form-item>
        <el-form-item>
          <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
          <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
        </el-form-item>
      </el-form>
      <el-row :gutter="10" class="mb8">
        <el-col :span="1.5">
            <el-button type="danger" plain icon="el-icon-delete" size="mini" :disabled="single" @click="handleDel"
            v-hasPermi="['admin:jishiApply:remove']">删除</el-button>
        </el-col>
        <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
      </el-row>
      <el-table v-loading="loading" :data="tabList" @selection-change="handleSelectionChange">
        <el-table-column type="selection" width="55" align="center" />
        <el-table-column label="技师姓名" align="center" prop="name" />
        <el-table-column label="技师电话" align="center" prop="phonenumber" />
        <el-table-column label="所在城市" align="center" prop="city" />
        <el-table-column label="技师年龄" align="center" prop="age" />
        <el-table-column label="技师性别" align="center" prop="sex" :formatter="sexChange"/>
        <el-table-column label="申请时间" align="center" prop="createTime"/>
        <el-table-column label="意向合作城市" align="center" prop="intentionCity" />
        <el-table-column label="技师照片" align="center" prop="photo">
          <template slot-scope="scope">
            <div @click="lookNotes(scope.row)" style="color:cornflowerblue;cursor: pointer;">点击查看</div>
          </template>
        </el-table-column>
      </el-table>
      <pagination v-show="total > 0" :total="total" :page.sync="queryParams.pageNum" :limit.sync="queryParams.pageSize" @pagination="getList" />
      <el-dialog :visible.sync="picShow" title="技师照片">
        <el-image style="width: 100px; height: 100px" :src="url.url"  v-for="url in srcList" :preview-src-list="[url.url]"> </el-image>
      </el-dialog>
    </div>
  </template>
    
  <script>
  import { jishiApplyList,areaList,jishiApplyDel} from "@/api/jishiManage/jishi";
  export default {
    name: "Knowledge",
    components: {
    },
    data() {
      return {
        picShow:false,
        srcList:[],
        // 遮罩层
        loading: false,
        // 显示搜索条件
        showSearch: true,
        // 总条数
        total: 0,
        // 选中数组
        ids: [],
        // 非单个禁用
        single: true,
        // 非多个禁用
        multiple: true,
        // 表格数据
        tabList: [],
        // 弹出层标题
        title: "",
        // 是否显示弹出层
        open: false,
        companyTypeOptions: [],
        // 查询参数
        queryParams: {
          pageNum: 1,
          pageSize: 10,
          name:null,
          phonenumber:null,
          birthday:null,
          sex:null,
          areaName:null,
        },
        areaNameArray:[],//城市
        sexArray:[],//性别
        birthdayData:'',
        birthday:'',
        birthdayEnd:'',
        createTimeDate:'',
        createDay:'',
        createDayEnd:''
      };
    },
    created() {
      this.getList();
      this.cityList()
      //在字典查询
      //性别
      this.getDicts("sys_user_sex").then(response => {
        this.sexArray = response.data;
      });
    },
    methods: {
      birthdayDataChange() {
        this.birthday = this.birthdayData[0] 
        this.birthdayEnd = this.birthdayData[1]
      },
      createTimeChange() {
        this.createDay = this.createTimeDate[0] 
        this.createDayEnd = this.createTimeDate[1]
      },
      /** 搜索按钮操作 */
      handleQuery() {
        this.queryParams.pageNum = 1;
        this.queryParams.birthday = this.birthday;
        this.queryParams.birthdayEnd = this.birthdayEnd;
        this.queryParams.createDay = this.createDay;
        this.queryParams.createDayEnd = this.createDayEnd;
        this.getList();
      },
      /** 重置按钮操作 */
      resetQuery() {
        this.birthdayData = ''
        this.birthday = ''
        this.birthdayEnd = ''
        this.createTimeDate = ''
        this.createDay = ''
        this.createDayEnd = ''
        this.resetForm("queryForm");
        this.handleQuery();
      },
      // 多选框选中数据
      handleSelectionChange(selection) {
        this.ids = selection.map(item => item.id)
        this.single = selection.length !== 1
        this.multiple = !selection.length
      },
      /** 查询产品入库列表 */
      getList() {
        this.loading = true;
        jishiApplyList(this.queryParams).then(response => {
          this.tabList = response.rows;
          this.total = response.total;
          this.loading = false;
        });
      },
      cityList(){
        areaList().then(response => {
          this.areaNameArray = response.data;
        });
      },
      sexChange(row){
        return this.selectDictLabel(this.sexArray, row.sex);
      },
      //查看备注
      lookNotes(row){
        this.srcList = [];
        if (row.photo){
          this.srcList = JSON.parse(row.photo)
        }
        this.picShow = true
      },
      //删除
      handleDel(){
        const id = this.ids;
        this.$confirm('确认删除技师信息', "警告", {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning"
        }).then(function() {
          return jishiApplyDel(id);
        }).then(() => {
          this.$message({message: '删除成功',type: 'success'});
          this.getList();

        })
      }
    }
  };
  </script>
  <style>
  </style>
    